{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<style>
  .layui-td-gray{width: 100px}
</style>
<form class="layui-form p-4">
  <h3 class="pb-3">客服配置</h3>
  <table class="layui-table layui-table-form">
    <input type="hidden" name="id" value="{$id}">
    <tr>
      <td class="layui-td-gray">客服电话</td>
      <td>
        <input type="text" name="kefu_mobile" lay-verify="required" autocomplete="off" placeholder="请输入客服电话"
               lay-reqText="请输入客服电话" class="layui-input" {notempty name="$config.kefu_mobile" }
               value="{$config.kefu_mobile}" {/notempty} style="display: inline-block;">
      </td>
    </tr>
    <tr>
      <td class="layui-td-gray">客服微信号</td>
      <td>
        <input type="text" name="kefu_wx" lay-verify="required" autocomplete="off" placeholder="请输入客服微信号"
               lay-reqText="请输入客服微信号" class="layui-input" {notempty name="$config.kefu_wx" }
               value="{$config.kefu_wx}" {/notempty} style="display: inline-block;">
      </td>
    </tr>
    <tr>
      <td class="layui-td-gray">客服二维码</td>
      <td>
        <div class="layui-upload">
          <button type="button" class="layui-btn layui-btn-sm" id="upload_btn_thumb">上传图片</button>
          <div class="layui-upload-list" id="upload_box_thumb">
            <img src="{$config.kefu_code}" width="100" style="width:150px;max-width:150px" />
            <input type="hidden" name="kefu_code" value="{$config.kefu_code}" lay-verify="required">
          </div>
        </div>
      </td>
    </tr>
  </table>

  <div class="py-3">
    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
  const moduleInit = ['tool','tinymce'];
  function gouguInit() {
    var form = layui.form, tool = layui.tool;

    //上传缩略图
    var upload_thumb = layui.upload.render({
      elem: '#upload_btn_thumb',
      url: '/admin/api/upload',
      done: function (res) {
        //如果上传失败
        if (res.code == 1) {
          return layer.msg('上传失败');
        }
        //上传成功
        $('#upload_box_thumb input').attr('value', res.data.filepath);
        $('#upload_box_thumb img').attr('src', res.data.filepath);
      }
    });

    //监听提交
    form.on('submit(webform)', function (data) {
      let callback = function (e) {
        layer.msg(e.msg);
        if (e.code == 0) {
          parent.layui.tool.close(1000);
        }
      }
      tool.post("/admin/conf/edit", data.field, callback);
      return false;
    });
  }
</script>
{/block}
<!-- /脚本 -->